
//
//  souSuoView.m
//  yiyou
//
//  Created by tangtangchitangtang on 2017/8/16.
//  Copyright © 2017年 tangtangchitangtang. All rights reserved.
//

#import "souSuoView.h"
#import "LayListTableViewCell.h"
#import "DetailedSelectionViewController.h"
#import "LawyerListTableViewCell.h"
#import "LCXQViewController.h"
#import "ContractListCollectionViewCell.h"
#import "CommodityDetailsViewController.h"
#import "LawProblemViewTableViewCell.h"
#import "LawDetailsViewController.h"
#import "SuccessCaseTableViewCell.h"
#import "DetailsSuccessViewController.h"
#import "ExpertDetailsViewController.h"
#import "ExpertListTableViewCell.h"
@implementation souSuoView

-(void)creatView{
    _tableView=[BaseTableView new];
    [self addSubview:_tableView];
    [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.left.right.mas_equalTo(0);
        make.top.mas_equalTo(NAV_HEIGHT);
    }];
    
    _tableView.delegate=self;
    _tableView.dataSource=self;
    _tableView.backgroundColor=_LightGrey;
    
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];

}
-(void)creatView2{
    UICollectionViewFlowLayout *flowLayout=[[UICollectionViewFlowLayout alloc] init];
    [flowLayout setScrollDirection:UICollectionViewScrollDirectionVertical];
    
    self.collectionView=[[UICollectionView alloc] initWithFrame:CGRectMake(0, NAV_HEIGHT, _mainW, _mainH-NAV_HEIGHT) collectionViewLayout:flowLayout];
    self.collectionView.dataSource=self;
    self.collectionView.delegate=self;
    [self.collectionView setBackgroundColor:[UIColor clearColor]];
    
    //注册Cell，必须要有
    [self.collectionView registerClass:[ContractListCollectionViewCell class] forCellWithReuseIdentifier:@"ContractListCollectionViewCell"];
    
    [self addSubview:self.collectionView];
//    _page=1;
    
    _collectionView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
        
//        [_collectionView.mj_footer endRefreshing];
//        [_collectionView.mj_header endRefreshing];
//        [_collectionArr removeAllObjects];
//        _page=1;
//        [self loadData];
    }];
    

}
-(NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
{
    return _tableArr.count;
}
//定义展示的Section的个数
-(NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
{
    return 1;
}


-(UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{
    
    ContractListCollectionViewCell *cell=[collectionView dequeueReusableCellWithReuseIdentifier:@"ContractListCollectionViewCell" forIndexPath:indexPath];
    
    cell.Dic=_tableArr[indexPath.row];
    [cell creatView];
    return cell;
    
}


//定义每个UICollectionView 的 margin
-(UIEdgeInsets)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout insetForSectionAtIndex:(NSInteger)section
{
    return UIEdgeInsetsMake(10, 10, 10, 10);
}

- (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return CGSizeMake(_mainW/2-15, _mainH/2.5);
}
-(void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
    CommodityDetailsViewController *xiangQing=[[CommodityDetailsViewController alloc] init];
    xiangQing.dic=_tableArr[indexPath.row];
    [ZQTools pushNextViewController:self.viewController andRootController:xiangQing];
    
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    
    // Return the number of sections.
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    return _tableArr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_abc==1) {
        LayListTableViewCell *cell=[[LayListTableViewCell alloc] init];
        cell.tableDic=_tableArr[indexPath.row];
        [cell creatView];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (_abc==3) {
        LawyerListTableViewCell *cell=[[LawyerListTableViewCell alloc] init];
        cell.dic=_tableArr[indexPath.row];
        [cell creatView];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (_abc==4) {
        LawProblemViewTableViewCell *cell=[[LawProblemViewTableViewCell alloc] init];
        
        cell.dic=_tableArr[indexPath.row];
        
        [cell creatView];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    if (_abc==5) {
        SuccessCaseTableViewCell *cell=[[SuccessCaseTableViewCell alloc] init];
        cell.dic=_tableArr[indexPath.row];
        [cell creatView];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }if (_abc==6) {
        ExpertListTableViewCell *cell=[[ExpertListTableViewCell alloc] init];
        cell.dic=_tableArr[indexPath.row];
        [cell creatView];
        tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
    return nil;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (_abc==1) {
        return 210;
    }
    if (_abc==3) {
         return 160;
    }
    if (_abc==4) {
        return 200;
    }if (_abc==5) {
        return 100;
    }
    if (_abc==6) {
        return 130;
    }
    return 0;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (_abc==1) {
        DetailedSelectionViewController *law=[[DetailedSelectionViewController alloc] init];
        law.dic=_tableArr[indexPath.row];
        [ZQTools pushNextViewController:self.viewController andRootController:law];;
    }
    if (_abc==3) {
        LCXQViewController *law=[[LCXQViewController alloc] init];
        law.dic=_tableArr[indexPath.row];
        [ZQTools pushNextViewController:self.viewController andRootController:law];;
    }if (_abc==4) {
        NSDictionary *dic=_tableArr[indexPath.row];
        NSNumber *news_id=[dic objectForKey:@"law_qa_id"];
        LawDetailsViewController *details=[[LawDetailsViewController alloc] init];
        details.law_qa_id=[NSString stringWithFormat:@"%@",news_id];
        [ZQTools pushNextViewController:self.viewController andRootController:details];
    }
    if (_abc==5) {
        NSDictionary *dic=_tableArr[indexPath.row];
        NSNumber *news_id=[dic objectForKey:@"classic_id"];
        DetailsSuccessViewController *details=[[DetailsSuccessViewController alloc] init];
        details.classic_id=[NSString stringWithFormat:@"%@",news_id];
        [ZQTools pushNextViewController:self.viewController andRootController:details];
    }if (_abc==6) {
        ExpertDetailsViewController *LSXQ=[[ExpertDetailsViewController alloc] init];
        LSXQ.dic=_tableArr[indexPath.row];
        [ZQTools pushNextViewController:self.viewController andRootController:LSXQ];
    }
    
//    else{
//        NSDictionary *dic=_tableArr[indexPath.row];
//        jingQuXiangQingViewController *xiangQing=[[jingQuXiangQingViewController alloc] init];
//        xiangQing.id=[dic objectForKey:@"id"];
//        [ZQTools pushNextViewController:self.viewController andRootController:xiangQing];
//    
//    }
}



@end
